package response;

import java.io.IOException;

import core.Constants;
import core.GamePacket;
import core.GameUser;

/**
 * According to the chat global request, this is the response
 * to broadcast the message to other users
 *
 * @author yiyi, genki
 *
 */
public class ResponseChatGlobal extends GameResponse {

    private int user_id;
    // Message sender's name
    private String userName;
    // Message
    private String message;

    public void setUserId(int user_id) {
        this.user_id = user_id;
    }

    /**
     * Set up the message sender
     * @param user		message sender
     */
    public void setUser(GameUser user) {
        userName = user.getUsername();
    }

    /**
     * Set up the message to be sent
     * @param readIn		message to be sent
     */
    public void setContent(String readIn) {
        message = readIn;
    }

    @Override
    public byte[] createResponse() {
        GamePacket packet = new GamePacket(code);
        packet.addUint32(user_id);
        packet.addString(userName); //Set the userName
        packet.addString(message);  //Set the greeting

        return packet.getBytes();
    }
}